package com.oimchat;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.onlyxiahui.aware.basic.extend.spring.context.annotation.AnnotationBeanFullNameGenerator;
import com.onlyxiahui.wofa.server.net.push.starter.EnableDataPush;

import java.util.Arrays;

@EnableTransactionManagement
@SpringBootApplication(exclude = {
		DruidDataSourceAutoConfigure.class })
@EnableDataPush
@ComponentScan(nameGenerator = AnnotationBeanFullNameGenerator.class)
public class SingleApplication {


	private static final String SPRING_CONFIG_NAME_KEY = "--spring.config.name";
	private static final String DEFAULT_SPRING_CONFIG_PARAM = SPRING_CONFIG_NAME_KEY + "=" + "oimserver";

	public static void main(String[] args) {
		SpringApplication.run(SingleApplication.class, updateArguments(args));
	}

	private static String[] updateArguments(String[] args) {
		if (Arrays.stream(args).noneMatch(arg -> arg.startsWith(SPRING_CONFIG_NAME_KEY))) {
			String[] modifiedArgs = new String[args.length + 1];
			System.arraycopy(args, 0, modifiedArgs, 0, args.length);
			modifiedArgs[args.length] = DEFAULT_SPRING_CONFIG_PARAM;
			return modifiedArgs;
		}
		return args;
	}
}
